package com.neusoft.elmboot.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.neusoft.elmboot.Dto.FoodDto;
import com.neusoft.elmboot.Vo.FoodVo;
import com.neusoft.elmboot.mapper.BusinessMapper;
import com.neusoft.elmboot.mapper.FoodMapper;
import com.neusoft.elmboot.po.FoodEntity;
import com.neusoft.elmboot.service.FoodService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class FoodServiceImpl extends ServiceImpl<FoodMapper, FoodEntity> implements FoodService {

    @Autowired
    private FoodMapper foodMapper;

    @Autowired
    private BusinessMapper businessMapper;

    @Transactional
    @Override
    public void delete(Long id) {
        FoodEntity food = foodMapper.selectById(id);

        /*BusinessEntity business = businessMapper.selectById(food.getBusinessId());
        if (business!=null){
            throw new BaseException("其他表中关联数据，无法删除!");

        }*/

        this.removeById(id);
    }

    @Override
    public void add(FoodDto foodDto) {
        FoodEntity foodEntity = new FoodEntity();
        BeanUtils.copyProperties(foodDto, foodEntity);


        foodEntity.setBusinessId(foodDto.getBusinessId());
        this.save(foodEntity);


    }

    @Override
    public List<FoodVo> getFoodVoList(List<Integer> list) {
        List<FoodVo> foodVoList = foodMapper.getFoodVoList(list);
        return foodVoList;
    }


}
